/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BusinessLogic;

import DTO.Manager;
import DataAccess.DataUtility;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Tran anh
 * @version 1.0
 */
public class LoginManagement {

    /**
     * Check in database which Manager has userName and PassWord same
     * with userName and passWord pass in.
     * that Manager must be  has status = 1.
     * if has then return object that Manager else return null
     * @param userName is specify Manager
     * @param passWord
     * @return a object Manger
     */
    public Manager login(String userName, String passWord){
        try {
            ResultSet rs = DataUtility.excuteQuery("Select * from ManagerAccount where status = 1 and userName = " + "\'" + userName + "\'" + " and passWord =" + "\'" + passWord + "\'");
            if(rs.next()){
                Manager m = new Manager();

                m.setName(rs.getString("Name"));
                m.setPassWord(rs.getString("passWord"));
                m.setPower(rs.getInt("power"));
                m.setUserName(rs.getString("UserName"));

                return m;
            }else{
                JOptionPane.showMessageDialog(null, "Error!! Please try again!");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
